package ControlLayer;

import ModelLayer.*;
import java.util.Set;
import java.util.HashMap;

public class RentalController
{
    private RentalContainer rentalCon;
    private Machine mac;
    
    
    public RentalController()
    {
        rentalCon = RentalContainer.getInstance();
    }
    
    public int getMachine()
    {
        return rentalCon.getMachineNo();
    }
    
    public boolean machineExists(int machineNo)
    {
        if (rentalCon.getMachine(machineNo) == null)
        {
            return false;
        }
        return true;
    }
    
    public void createMachine(String name, String description, 
                    boolean machineStatus, int price)
    {
        int machineNo = rentalCon.getMachineNo();
        Machine newMachine = new Machine(name, machineNo, description, machineStatus, price);
        rentalCon.addMachine(machineNo, newMachine);
    }
    
    public boolean updateMachine(String name,int machineNo, String description, int price)
    {
        Machine machine = rentalCon.getMachine(machineNo);
        machine.setName(name);
        machine.setDescription(description);
        machine.setPrice(price);
        return true;
    }
    
    public Machine findMachine(int machineNo) throws Exception
    {
        Machine machine = rentalCon.findMachineByMachineNo(machineNo);
        if(machine == null)
        {
            throw new Exception("No machine found with that number");
        }
        return machine;
    }
    public boolean getStatus(int machineNo)
    {
        boolean machine = false;
        try{
            machine = findMachine(machineNo).getMachineStatus();
        
        }
        catch(Exception e)
                {
                    System.out.println("FORKERT");
                }
        return machine;
        //return mac.getMachineStatus();
    }
    public void rentMachine(int machineNo) throws Exception{
    
        Machine machine = findMachine(machineNo);
        machine.setMachineStatus(true);
    }
    
    public void machineDelivered(int machineNo) throws Exception
    {
        Machine machine = findMachine(machineNo);
        machine.setMachineStatus(false);
    }
    
    public void removeMachine(int machineNo)
    {
        rentalCon.removeMachine(machineNo);
    }
    public HashMap<Integer, Machine> getRentalContainer()
    {
        return rentalCon.getRental();
    }
}
